package com.cq.hd.app.controller;

import com.cq.hd.common.annotation.LoginUser;
import com.cq.hd.common.entity.AppLoginUser;
import com.cq.hd.common.entity.BusinessInfo;
import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.member.api.TbMerchantEnterApplyApi;
import com.cq.hd.member.api.dto.AppMerchantEnterApplyPageDto;
import com.cq.hd.member.api.dto.MerchantEnterAuditDto;
import com.cq.hd.member.api.vo.AppMerchantEnterApplyPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequestMapping("/merchantEnterApply")
@Api(tags = "商户入驻相关接口")
public class MerchantEnterApplyController {

    @Autowired
    private TbMerchantEnterApplyApi merchantEnterApplyApi;

    @ApiOperation(value = "商户入驻审核列表")
    @ApiImplicitParam(name = "appMerchantEnterApplyPageDto", value = "实体", required = true, paramType = "query", dataType = "AppMerchantEnterApplyPageDto")
    @ApiResponse(response = AppMerchantEnterApplyPageVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/page")
    public Result<Page<AppMerchantEnterApplyPageVo>> pageAppMerchantEnterApply(AppMerchantEnterApplyPageDto appMerchantEnterApplyPageDto,
                                                                               @ApiIgnore @LoginUser AppLoginUser appLoginUser) {
        appMerchantEnterApplyPageDto.setUserId(appLoginUser.getUserId());
        BusinessInfo businessInfo = appLoginUser.getUserInfo().getBusinessInfo();
        if (businessInfo != null) {
            appMerchantEnterApplyPageDto.setBusinessId(businessInfo.getId());
        }

        return merchantEnterApplyApi.pageAppMerchantEnterApply(appMerchantEnterApplyPageDto);
    }

    @ApiOperation(value = "商户入驻详情")
    @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "Long")
    @ApiResponse(response = AppMerchantEnterApplyPageVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/details")
    public Result<AppMerchantEnterApplyPageVo> details(Long id) {
        return merchantEnterApplyApi.details(id);
    }

    @ApiOperation(value = "商户入驻审核")
    @ApiImplicitParam(name = "merchantEnterAuditDto", value = "实体", paramType = "body", dataType = "MerchantEnterAuditDto")
    @PostMapping("/audit")
    public Result<Boolean> audit(@RequestBody MerchantEnterAuditDto merchantEnterAuditDto) {
        return merchantEnterApplyApi.audit(merchantEnterAuditDto);
    }

}
